﻿using Google.Protobuf;
using Server.Framework.Message;
using Server.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server.Message.Response
{
    /// <summary>
    /// Author: Leil
    /// Description: 角色列表回复消息
    /// CreateTime: 2020/5/13 12:31:32
    /// </summary>
    class OrgTreeResp : ResponseBaseMessage
    {
        public List<OrgDao> Orgs { get; } = new List<OrgDao>();

        public int HasRoot { get; set; }

        public OrgTreeResp(int msgId):base(msgId)
        {

        }

        public override byte[] Serialize()
        {
            ResponseOrgTree msg = new ResponseOrgTree()
            {
                HasRoot = HasRoot
            };

            Orgs.ForEach(org =>
            {
                msg.Orgs.Add(new Org()
                {
                    Id = org.ID,
                    ParentId = org.ParentId,
                    OrgName = org.OrgName ?? string.Empty,
                });
            });
            return msg.ToByteArray();
        }
    }
}
